<?php
defined('_AppMiage') or die('Restricted access');

$IdsDomaine = $_POST["Values"]["domaine"];
$IdsTechno = $_POST["Values"]["techno"];
$IdsCategorie = $_POST["Values"]["categories"];
$IdsPromo = $_POST["Values"]["promo"];
if(empty($IdsDomaine))
    $IdsDomaine=array();
if(empty($IdsTechno))
    $IdsTechno=array();
if(empty($IdsCategorie))
    $IdsCategorie=array();
if(empty($IdsPromo))
    $IdsPromo=array();

if(isset($_POST["Values"]["page"]) && !empty($_POST["Values"]["page"]))
{
    $nbr = (((int) $_POST["Values"]["page"] - 1) * $nbrResultPerPage);
    $lstOffres = Offre::getListOffrePortailByCritere($nbrResultPerPage, $nbr,$IdsCategorie,$IdsDomaine,$IdsTechno,$IdsPromo);
}
else
{
    $lstOffres = Offre::getListOffrePortailByCritere($nbrResultPerPage, 0,$IdsCategorie,$IdsDomaine,$IdsTechno,$IdsPromo);
}

$i = 1;
if(!empty($lstOffres))
{
    foreach ($lstOffres as $o)
    {
        $offre = new Offre($o->IdOffre);
        $contactEntreprise = new ContactEntreprise($offre->getIdContactEntreprise());
        $entreprise = new Entreprise($contactEntreprise->getIdEntreprise());
        ?>
        <div class="post <?php if ($i % 2 == 0){ echo 'post-even'; } ?> <?php if($i==1){ echo "firstimport";} ?>" id="post-<?php echo $offre->getIdOffre(); ?>">
            <h2 class="title">
                <a href="<?php echo URL . "/index.php?m=view_offre&id=" . $offre->getIdOffre(); ?>" rel="bookmark" title="Visualiser l'offre">
                    <?php echo stripcslashes($offre->getTitreOffre()); ?>
                </a>
                <?php if($offre->getStatutOffre() == "convoitee"): ?>
                    <span class="alreadyuse">Convoit&eacute;e</span>
                <?php endif; ?>
            </h2>
            <div class="subtitleoffre">
                <label>Entreprise :</label>
                    <span class="link"><?php echo stripcslashes($entreprise->getNomEntreprise()); ?></span>
                <label  style="margin-left:10px;">Domaine :</label>
                    <a href="<?php echo URL; ?>index.php?m=offres&dom=<?php echo $offre->getIdDomaineApplication(); ?>" class="link"> <?php $dom = new DomaineApplication($offre->getIdDomaineApplication()); echo $dom->getNomDomaineApplication(); ?></a>
                <label  style="margin-left:10px;">Ville :</label>
                    <span class="link"><?php echo stripcslashes($entreprise->getVilleEntreprise()); ?></span>
                <label style="margin-left:10px">Promo : </label>
                    <a href="<?php echo URL; ?>index.php?m=offres&promo=<?php echo $offre->getIdPromo(); ?>" class="link"><?php echo Promo::getPromoById($offre->getIdPromo()); ?></a>
            </div>
            <div class="entry">
                <?php echo stripcslashes($offre->getDescriptionOffre()); ?><br/>
                <div class="readmore">
                    <b>
                        <a href="<?php echo URL . "index.php?m=view_offre&id=" . $offre->getIdOffre(); ?>" rel="bookmark" title="Visualiser l'offre">
                            Plus de d&eacute;tails &raquo;
                        </a>
                    </b>
                </div>
            </div>
        </div>
        <?php
        $i += 1;
    }
}
elseif($_POST["Values"]["page"] == 1 && empty($lstOffres))
{
    echo "FAIL<div class='notice'>Aucun résultat ne correspond à votre recherche.</div>";
}
else
{
    echo "FAIL";
}

?>